@isTest
private class QuoteAboardControllerTest {
    static testMethod void testMethod1() {
        

         Account acc = TestUtils.createAccount();
        acc.Name = '客户A';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerAbroad','Account');
        insert acc;

         // 业务机会
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        opp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('OverseaDearlerOpportunity', 'Opportunity');
        insert opp;


      	
      	Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '试剂';
        p1.PriceCompany__c = 'MKSY';
        p1.ProductName__c = '测试试剂';
        p1.NCCode__c = '000001';
        p1.Brand__c = '迈克';//
        p1.Overseasproducts__c = true;
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert p1;
        System.debug('QuoteAboardControllerTest==>'+p1);


        // 意向产品
        IntentProduct__c ip = TestUtils.createIntentProduct();
        ip.Opportunity__c = opp.Id;
        ip.Product__c = p1.Id;
        insert ip;

        User u = [select Id ,SubCompany__c ,PriceProvince__c from User where Id=:UserInfo.getUserId()];
        // 价格
        Price__c price = TestUtils.createPrice();
        price.Product__c = p1.Id;
        price.Company__c = u.SubCompany__c ;
        price.InstCost__c = 10.0;
        price.MarketPriceUSD__c = 10; 
        insert price; 

        QuoteAboardController.matchProduct(new List<String>{'000001'},u.SubCompany__c,u.PriceProvince__c);
          //新建
        PageReference page = new PageReference('/apex/QuoteAboard?id=' + opp.Id );
        System.Test.setCurrentPage(page);
        QuoteAboardController qbc = new QuoteAboardController();
        qbc.init();

        Map<String,String> searchMap = new Map<String,String>();
        searchMap.put('NCCode__c','000001');
        System.debug([select Id ,ProductName__c,Overseasproducts__c ,SerialNo__c ,Model__c, Brand__c ,Spec__c,
            Category0__c,NCCode__c ,Category1__c ,SealCompany__c  from Product__c  ]);

        /*
        System.debug([select Id ,ProductName__c ,SerialNo__c ,Model__c, Brand__c ,Spec__c,
            Category0__c,NCCode__c ,Category1__c ,SealCompany__c from Product__c 
            where   Category0__c !='仪器' and (Overseasproducts__c  = true  or Brand__c like '%迈克%') 
             and NCCode__c like '%000001%'  limit 200 ]);
        */
        qbc.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap),'UTF-8');
        qbc.search();
        List<Object> details = (List<Object>)JSON.deserializeUntyped( EncodingUtil.urlDecode(qbc.dataJson, 'UTF-8'));
        Map<String,Object> d = (Map<String,Object> ) details.get(0);
        d.put('marketprice', 10);

         Map<String,Object>saveMap = new Map<String,Object>();
        saveMap.put('detail',details);
        System.debug('QuoteAboardControllerTest==>'+saveMap);
         qbc.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap),'UTF-8');
        qbc.save();
        System.debug('QuoteAboardControllerTest==>'+qbc.msg);
        //编辑 
        Quote q = [select Id from Quote where OpportunityId =:opp.Id ];
        PageReference page1 = new PageReference('/apex/QuoteAboard?id=' + q.Id );
        System.Test.setCurrentPage(page1);
        QuoteAboardController qbc1 = new QuoteAboardController();
        qbc1.init();

        //ContractWebService.postOverseaQuote(q.Id, false);


    }
}